/**
 *	\file
 *	\brief indicates a single cell of the hash table which will contain all the resources of a particular class
 *
 *
 *
 * 	\date Sep 20, 2013
 * 	\author koldar
 *	\version 1.0
 */

#ifndef RESOURCEHTCELL_H_
#define RESOURCEHTCELL_H_

#include "ResourceElement.h"
#include "uthash.h"

//TODO documentation
/**represents a single cell in the hash table storing resources of a particular class
 *
 */
typedef struct ResourceHTCell {
	char* key;
	PresourceElement resource;
	UT_hash_handle hh;
} ResourceHTCell;

/**points to a cell storing a class resource
 *
 */
typedef ResourceHTCell* PresourceHTCell;

/**initialize correctly an hashtable cell. It can be freed with freeResourceHTCell().
 *
 * \pre
 *  \li _resource not NULL
 * \post
 *  \li a new element of the hash table that can be added to it;
 *  \li the key associated to the value _resource is the field "name" of the object _resource
 *
 * @param _resource the structure to be decorated to be am hash table cell
 * @return a pointer to the newly created ResourceHTCell
 */
PresourceHTCell initResourceHTCell(PresourceElement _resource);

/**Frees correctly a hash table cell
 *
 * \pre
 *  \li pcell must not be NULL
 * \post
 *  \li pcell is correctly freed from memory
 *
 * @param _resource the cell to be deallocated
 */
void freeResourceHTCell(PresourceHTCell _resource);

/**print a string representation of this hash table cell
 *
 * \pre
 *  \li f open in write mode;
 *  \li pcell not NULL;
 * \post
 *  \li f changed;
 *  \li in f the cell is represented by the expression: "[ key -> value ]"
 *
 * @param f the file to write on
 * @param pcell the cell to write
 */
void printResourceHTCell(FILE* f,PresourceHTCell pcell);

/**writes in f a code block that can be interpreted as a node in DOT language.
 * This function should be used to automatically generate DOT file representing
 * a resource hash table.
 *
 * \pre
 *  \li f open in write mode;
 * \post
 *  \li in f there is a piece of code <b>not</b> immidiately compilable by dot;
 *  \li in f there is a piece of code representing this cell;
 *
 *
 * @param f the file to write on
 * @param pcell the cell to write
 * @param nodenumber the number of the dot node identifier. For example if you pass 53 then the ID will be n053. The regex is n%03d
 * @param htcellnumber represents the cell in memory where to store the ID of the node representing this ResourceHTCell
 * @param format indicates the number of '\t' characters that will be added before every line generated by this function (for indentation purpose)
 */
void generateDOTResourceHTCell(FILE *f, PresourceHTCell pcell,int* nodenumber,int* htcellnumber, int format);

#endif /* RESOURCEHTCELL_H_ */
